package com.demo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * 缓存控制层
 * @author chenyongjiu
 */
@Slf4j
@RestController
public class CacheController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 测试lettuce客户端连接redis
     * @return 返回当前时间戳
     */
    @GetMapping("/concurrent/req/redis")
    public String concurrentReqRedisFromLettuce() {
        String i = String.valueOf(System.currentTimeMillis());
        stringRedisTemplate.opsForValue().set(i, i, 60, TimeUnit.SECONDS);
        log.info("缓存key：{}", i);
        return i;
    }
}
